package com.dodo.blog.ui.component.composite;

import com.dodo.blog.RequestCycle;
import com.dodo.blog.WebApplication;
import com.dodo.blog.ui.component.container.Form;
import com.dodo.blog.ui.component.container.Li;
import com.dodo.blog.ui.component.container.Nav;
import com.dodo.blog.ui.component.container.Ul;
import com.dodo.blog.ui.component.input.Anchor;
import com.dodo.blog.ui.component.input.TextBox;
import com.dodo.blog.ui.page.Page;

import static com.dodo.blog.ui.util.Localization.localize;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public class NavigationPanel
        extends Nav
{
    public NavigationPanel( Class<? extends Page>... pages )
    {
        Ul menu = new Ul();
        add( menu );

        for ( Class<? extends Page> page : pages )
        {
            Li menuItem = new Li();
            Anchor link = new Anchor( localize( "menu." + page.getSimpleName().toLowerCase() ), page );
            menuItem.add( link );
            if ( WebApplication.get().getPageClassByPath( RequestCycle.get().getRequest().getServletPath() ) == page )
            {
                link.setClassName( "selected" );
            }

            menu.add( menuItem );
        }

        // TODO: implement search
        Form form = new Form( "search-form" );
        form.add( new TextBox( "search" ).setPlaceHolder( localize( "placeholder.search" ) ) );
        add( form );
    }
}
